<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_block_GenericFolderListAction extends m_backoffice_extends_Action
{


	public function execute()
	{
		$moduleName = $this->getRequestParameter("configModule");
        $listService = m_backoffice_services_ListService::getInstance()->getXmlFilePath($moduleName);
        
		$parentDoc = $this->getDocumentProvider()->getByUniqueId($this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));
		$isTabbed = $this->getRequestParameter("tabbed");
		$tabName = $this->getRequestParameter("tabName");
		$params = $listService->getXmlConfig($parentDoc);

        //Sort and search parameters
        $sortParams = $listService->getSortParams($moduleName, $this->getRequestParameter("column"), $this->getRequestParameter("order"));
        $searchParams = $listService->getSearchParams($moduleName, $this->getRequestParameter("searchValues"));

        //Get the nbDocTot;
        $nbDocTot = $listService->getDocumentsByModuleName($parentDoc, null, null, array(), $searchParams, true);
        $pagination = $listService->pagination($moduleName, $nbDocTot, $this->getRequestParameter("numPage"), $this->getRequestParameter("nbDoc"), $listService->getDefaultNbDoc());

		$documents = array();
		$columns = array();
		if($tabName == "files" || $tabName == "")
		{
			$documents = $listService->getDocumentsByModuleName($parentDoc, $pagination["nbDoc"], $pagination["numPage"], $sortParams, $searchParams);
            $columns = $listService->getColumns();
		}

        $this->addToModel("isSortable", $listService->isSortable());
        $this->addToModel("moduleName", $moduleName);
        $this->addToModel("docSearchParams", $searchParams);
        $this->addToModel("searchParams", $this->getContext("searchParams_".$moduleName));
        $this->addToModel("sortParams", $sortParams);
        $this->addToModel("pagination", $pagination);
		$this->addToModel("documents", $documents);
		$this->addToModel("columns", $columns);
		$this->addToModel("tabName", $tabName);		
		$this->addToModel("isTabbed", $isTabbed);		
		$this->addToModel("folder", $parentDoc);		
		$this->addToModel("params", $params);
		$this->setView('success');
	}
}